﻿using CommonUtils;
using Test.Core.Web;
using LinqKit;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System;

namespace web_api.Controllers
{
    [SwaggerTag("充值码")]
    public class RechargeCodeController : DbController<Db, RechargeCode>
    {
        [HttpGet]
        [SwaggerOperation("单项查询")]
        public ApiResult<RechargeCode> Query(
            [SwaggerParameter("主键ID")] string? id,
            [SwaggerParameter("Value")] string? value,
            [SwaggerParameter("CreateTime")] DateTime? createTime,
            [SwaggerParameter("Consumed")] bool? consumed,
            [SwaggerParameter("ConsumTime")] DateTime? consumTime)
        {
            var query = NewQuery()
            .And(id.IsNotEmpty(), m => m.Id == id)
                     .And(value.IsNotEmpty(), m => m.Value == value)
            .And(createTime.IsNotEmpty(), m => m.CreateTime == createTime)
            .And(consumed.IsNotEmpty(), m => m.Consumed == consumed)
            .And(consumTime.IsNotEmpty(), m => m.ConsumTime == consumTime);
            return ApiResult.Ok(Db.Query(query));
        }

        [HttpGet]
        [SwaggerOperation("列表查询")]
        public ApiResult<RechargeCode[]> List(
            [SwaggerParameter("Value")] string? value,
            [SwaggerParameter("CreateTime")] DateTime? createTime,
            [SwaggerParameter("Consumed")] bool? consumed,
            [SwaggerParameter("ConsumTime")] DateTime? consumTime)
        {
            var query = NewQuery()
                  .And(value.IsNotEmpty(), m => m.Value == value)
            .And(createTime.IsNotEmpty(), m => m.CreateTime == createTime)
            .And(consumed.IsNotEmpty(), m => m.Consumed == consumed)
            .And(consumTime.IsNotEmpty(), m => m.ConsumTime == consumTime);
            return ApiResult.Ok(Db.List(query));
        }

        [HttpGet]
        [SwaggerOperation("分页查询")]
        public ApiResult<Page<RechargeCode>> Page(
            [SwaggerParameter("Value")] string? value,
            [SwaggerParameter("CreateTime")] DateTime? createTime,
            [SwaggerParameter("Consumed")] bool? consumed,
            [SwaggerParameter("ConsumTime")] DateTime? consumTime,
            [SwaggerParameter("页码")] int? pageNum,
            [SwaggerParameter("页容")] int? pageSize)
        {
            var query = NewQuery()
            .And(value.IsNotEmpty(), m => m.Value == value)
            .And(createTime.IsNotEmpty(), m => m.CreateTime == createTime)
            .And(consumed.IsNotEmpty(), m => m.Consumed == consumed)
            .And(consumTime.IsNotEmpty(), m => m.ConsumTime == consumTime);
            return ApiResult.Ok(Db.Page(pageNum, pageSize, query));
        }
    }
}
